package org.example.day09;

/**
 * 第三章节3.2.4: 方法join(long)的使用
 *      ①m4.join(8000); 如果m4线程执行时间x < 8s 则main线程等待x秒.
 *      ②m4.join(8000); 如果m4线程执行的时间y > 8s 则main线程只等待8s.
 */
public class MyThread4 extends Thread{
    @Override
    public void run() {
        try {
            System.out.println("run begin time = " + System.currentTimeMillis());
            Thread.sleep(5000);
            System.out.println("run end time = " + System.currentTimeMillis());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        try {
            MyThread4 m4 = new MyThread4();
            m4.start();
            System.out.println("main begin time = " + System.currentTimeMillis());
            m4.join(8000); //m4线程插队，但是main线程只等待了两秒
            System.out.println("main end time = " + System.currentTimeMillis());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
